home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / timer / ds3100.md / timerTick.c < prev    next >
C/C++ Source or Header  |  1990-09-06  |  4KB  |  174 lines

  1. /*
  2.  * timerTick.c --
  3.  *
  4.  *    Kernel utility procedures to manipulate time Tick values for the PMAX.
  5.  *
  6.  * Copyright (C) 1989 Digital Equipment Corporation.
  7.  * Permission to use, copy, modify, and distribute this software and
  8.  * its documentation for any purpose and without fee is hereby granted,
  9.  * provided that the above copyright notice appears in all copies.  
  10.  * Digital Equipment Corporation makes no representations about the
  11.  * suitability of this software for any purpose.  It is provided "as is"
  12.  * without express or implied warranty.
  13.  */
  14.  
  15. #ifndef lint
  16. static char rcsid[] = "$Header: /sprite/src/kernel/timer/ds3100.md/RCS/timerTick.c,v 9.0 89/09/12 15:21:39 douglis Stable $ SPRITE (DECWRL)";
  17. #endif not lint
  18.  
  19. #include "sprite.h"
  20. #include "mach.h"
  21. #include "timerTick.h"
  22. #include "spriteTime.h"
  23. #include "sys.h"
  24.  
  25. #define ONE_MILLION    1000000
  26.  
  27. /*
  28.  * Some commonly used values for intervals.
  29.  */
  30.  
  31. Timer_Ticks    timer_TicksZeroSeconds;
  32. unsigned int    timer_IntZeroSeconds;
  33. unsigned int    timer_IntOneSecond;
  34. unsigned int    timer_IntOneMillisecond;
  35. unsigned int    timer_IntOneMinute;
  36. unsigned int    timer_IntOneHour;
  37.  
  38.  
  39. /*
  40.  *----------------------------------------------------------------------
  41.  *
  42.  * TimerTicksInit --
  43.  *
  44.  *    Initializes the various tick and interval values.
  45.  *
  46.  * Results:
  47.  *    None.
  48.  *
  49.  * Side effects:
  50.  *    None.
  51.  *
  52.  *----------------------------------------------------------------------
  53.  */
  54. void
  55. TimerTicksInit()
  56. {
  57.     timer_IntOneMillisecond = 1000;
  58.     timer_IntOneSecond = ONE_MILLION;
  59.     timer_IntZeroSeconds = 0;
  60.     timer_IntOneMinute = timer_IntOneSecond * 60;
  61.     timer_IntOneHour = timer_IntOneSecond * 3600;
  62.     bzero((Address)&timer_TicksZeroSeconds, sizeof(timer_TicksZeroSeconds));
  63. }
  64.  
  65. /*
  66.  *----------------------------------------------------------------------
  67.  *
  68.  *  Timer_AddTicks --
  69.  *
  70.  *     Adds two tick values together.
  71.  *
  72.  *
  73.  *  Results:
  74.  *    A time in ticks.
  75.  *
  76.  *  Side effects:
  77.  *    None.
  78.  *
  79.  * This is macro defined in timerTick.h
  80.  * #define Timer_AddTicks(a,b,c)        Time_Add(a,b,c)
  81.  *
  82.  *----------------------------------------------------------------------
  83.  */
  84.  
  85.  
  86. /*
  87.  *----------------------------------------------------------------------
  88.  *
  89.  *  Timer_SubtractTicks --
  90.  *
  91.  *     Subtracts the second parameter from the first parameter. 
  92.  *    The second parameter must be less than the first, otherwise 
  93.  *    a zero tick value is returned.
  94.  *
  95.  *  Results:
  96.  *    An absolute time in ticks.
  97.  *
  98.  *  Side effects:
  99.  *    None.
  100.  *
  101.  * This is macro defined in timerTick.h
  102.  * #define Timer_SubtractTicks(a,b,c)    Time_Subtract(a,b,c)
  103.  *----------------------------------------------------------------------
  104.  */
  105.  
  106.  
  107. /*
  108.  *----------------------------------------------------------------------
  109.  *
  110.  *  Timer_AddIntervalToTicks --
  111.  *
  112.  *     Adds an interval (32-bit value) to an absolute time (64-bit value).
  113.  *
  114.  *  Results:
  115.  *    An absolute time in ticks.
  116.  *
  117.  *  Side effects:
  118.  *    None.
  119.  *
  120.  *----------------------------------------------------------------------
  121.  */
  122. void
  123. Timer_AddIntervalToTicks(absolute, interval, resultPtr)
  124.     Timer_Ticks        absolute;    /* Addend 1 */
  125.     unsigned int    interval;    /* Addend 2 */
  126.     Timer_Ticks        *resultPtr;    /* Sum */
  127. {
  128.     Time    intTime;
  129.  
  130.     intTime.seconds = interval / ONE_MILLION;
  131.     intTime.microseconds = interval % ONE_MILLION;
  132.     Time_Add(absolute, intTime, resultPtr);
  133. }
  134.  
  135.  
  136. /*
  137.  *----------------------------------------------------------------------
  138.  *
  139.  *  Timer_TicksToTime --
  140.  *
  141.  *      Converts a Timer_Ticks value into a Time value.
  142.  *
  143.  *  Results:
  144.  *    A time value in Time format.
  145.  *
  146.  *  Side effects:
  147.  *    None.
  148.  *
  149.  *    This routine is #defined to be *timePtr = tick;
  150.  * #define Timer_TicksToTime(a,b)        *(b) = a;
  151.  *----------------------------------------------------------------------
  152.  */
  153.  
  154.  
  155. /*
  156.  *----------------------------------------------------------------------
  157.  *
  158.  *  Timer_TimeToTicks --
  159.  *
  160.  *      Converts a Time value into a Timer_Ticks value.
  161.  *
  162.  *  Results:
  163.  *    A time value in ticks.
  164.  *
  165.  *  Side effects:
  166.  *    None.
  167.  *
  168.  *  This routine is #defined to be *ticksPtr = time;
  169.  *
  170.  *  #define Timer_TimeToTicks(a,b)        *(b) = a;
  171.  *----------------------------------------------------------------------
  172.  */
  173.  
  174.